<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../../../../lib/html5shiv.js?rev=@@hash"></script>
    <script type="text/javascript" src="../../../../lib/respond.min.js?rev=@@hash"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../../../static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../../../static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="../../../../lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../../../../static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="../../../../static/h-ui.admin/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../../../ht-css/Project.css"/>
    <!--时间选择器样式-->
    <link rel="stylesheet" type="text/css" href="../../../../ht-css/jedate.css" />
    <!--引入分页-->
    <link rel="stylesheet" href="../../../../lib/pagination/pagination.css">
    <!--表单验证-->
    <script type="text/javascript" src="../../../../lib/Validform/5.3.2/Validform_v5.3.2_min.js?rev=@@hash"></script>
    <link rel="stylesheet" type="text/css" href="../../../../lib/Validform/5.3.2/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="../../../../lib/DD_belatedPNG_0.0.8a-min.js?rev=@@hash"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../../../ht-css/style-q.css"/>
    <style type="text/css">
        .dis_btn {
            background: #9c9a9a;
            color: #fff;
            border: 1px solid #9c9a9a;
        }

        .dis_btn:hover {
            background: #9c9a9a;
            color: #fff;
            border: 1px solid #9c9a9a;
        }
    </style>
    <title>商品管理</title>
</head>
<body data-id="83">
<nav class="breadcrumb">商品管理 <span class="c-gray en">&gt;</span> 商品售卖管理 <span class="c-gray en">&gt;</span> sku商品名称<a
        class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
        href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<article class="page-container">
    <div class="ml-20 mr-20" id="form-member-add">
        <div id="tab_topnav" class="HuiTab">
            <div class="tabBar clearfix"><span>商品售卖管理</span><!--<span>商品图片管理</span>--></div>
            <!--SKU列表-->
            <div class="tabCon pd-5 bg-1 bk-gray pb-10" id="productSkuManage">
                <div class="lh-30 pd-10">
                    <form action="" id="goodSkuForm">
                        <table class="table-hover table_li ml-10 mb-10 table">
                            <thead class="text-l">
                            <tr>
                                <td colspan="1">
                                    <div style="margin:0 auto; overflow: hidden; display: inline-block;">
                                        <div class="form-label f-l pt-5" id="spuId_title">
                                            SPU：
                                        </div>
                                    </div>
                                </td>
                                <td colspan="1">
                                    <div style="margin:0 auto; overflow: hidden; display: inline-block;">
                                        <div class="form-label f-l pt-5" id="spuName_title">
                                            商品名称：
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>

                                <td class="col-3-1">
                                    <div class="row ml-10">
                                        <label class="form-label f-l text-r w-75 lh-26">Code码：</label>
                                        <div class="formControls f-l">
                                            <input type="text" class="input-text radius ml-10 w-180" name="productCode" id="productCode" placeholder="输入Code码" datatype="*0-15" errormsg="格式错误，请重新输入"
                                                   ignore="ignore">
                                        </div>
                                        <span class="Validform_checktip"></span>
                                    </div>
                                </td>
                                <td class="col-3-1">
                                    <div class="row ml-10">
                                        <label class="form-label f-l text-r w-75 lh-26">规格名称：</label>
                                        <div class="formControls f-l">
                                            <input type="text" class="input-text radius ml-10 w-180" name="saleAttriValue"
                                                   id="saleAttriValue" placeholder="输入规格关键字"
                                                   datatype="*0-15" errormsg="格式错误，请重新输入"
                                                   ignore="ignore">
                                        </div>
                                        <span class="Validform_checktip"></span>
                                    </div>
                                </td>

                                <td class="col-3-1">
                                    <div class="row ml-10">
                                        <label class="form-label f-l text-r w-55" style="width: 60px;">集团状态：</label>
                                        <div class="formControls col-sm-8 pos-r">
                                            <select class="select radius f-l ml-10" style="width:82%; height: 27px;margin-top: -4px;margin-left: 1px;" id="proUseable">
                                                <option selected value="-1">请选择</option>
                                                <option value="0">启用</option>
                                                <option value="1">禁用</option>
                                            </select>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td class="col-3-1">
                                    <div class="row ml-10">
                                        <label class="form-label f-l pt-5" style="margin-left: 15px;">创建时间：</label>
                                        <div class="f-l">
                                            <input class="workinput wicon input-text radius" id="creatimemin" type="text" placeholder="起始时间" style="width:115px;margin-left: 9px;" readonly>
                                            ~
                                            <input class="workinput wicon input-text radius" id="creatimemax" type="text" placeholder="结束时间" style="width:115px;" readonly>
                                        </div>
                                        <div class="f-l ml-50"><span class="timeError pl-30" style="color: red;"></span></div>
                                    </div>
                                </td>
                                <td class="col-3-1">
                                    <div class="row ml-10">
                                        <label class="form-label f-l lh-26 w-75 text-r">商品类型：</label>
                                        <select class="select radius ml-10 f-l specialTypeId" style="width:44%;height:30px;"  name="saleStatus" size="1">

                                        </select>
                                    </div>
                                </td>
                                <td class="col-3-1"></td>
                            </tr>
                            </thead>
                        </table>
                        <div class="text-c mb-10">
                            <input id="bottm" type="submit" class="btn btn-secondary radius size-S botter powerButton 1000001954909102" value="&nbsp;查&nbsp;&nbsp;询&nbsp;">
                            <input name="" type="reset" onclick="resetDiv()" class="btn radius size-S botter ml-10 powerButton 1000001954909102" value="&nbsp;重&nbsp;&nbsp;置&nbsp;">
                        </div>
                    </form>
                </div>
                <table class="table table-border table-bordered table-hover table-bg table-sort mt-10 goods_sku_ku"
                       id="datatable">
                    <thead>
                    <tr class="text-c">
                        <th width="50"><input type="checkbox" onclick="stopProp()" value="spu_all" id="spu_all">商品码</th>
                        <th width="50">规格名称</th>
                        <th width="50">计量单位</th>
                        <th width="50">件装数量</th>
                        <th width="100">商品类型</th>
                        <th width="100">集团状态</th>
                        <th width="50">场景标签</th>
                        <th width="50">商品尺寸(单品)</th>
                        <th width="50">创建时间</th>
                        <th width="50">操作</th>
                    </tr>
                    </thead>
                    <tbody class="shun">
                    </tbody>
                </table>
                <div class="dataTables_wrapper goods_fanye clearfix">
                    <div class="f-r pageturning M-box4"></div>
                </div>
            </div>

            <!--商品图片管理-->
            <div class="tabCon pd-5 bg-1 bk-gray pb-10">
                <div class="lh-30 pd-10">
                    <form name="name2" id="picForm">
                        <table class="table-hover table_li ml-10 mb-10 table">
                            <thead class="text-l">
                            <tr>
                                <td colspan="3" class="col-1-1">
                                    <div class="row ml-10">
                                        <label class="form-label f-l pt-5">商品分类：</label>
                                        <span class="size-M radius col-xs-8 f-l" style="width:15%">
                                     <div style="position: relative;z-index: 900;">
                                          <input type="text" autocomplete="off" class="input-text radius"
                                                 name="imgClass1" placeholder="请选择一级分类"
                                                 oninput="imgGoods_listCategory(1)" id="imgClass1"
                                                 datatype="/^[a-zA-Z0-9\u4e00-\u9fa5、]{0,20}$/" errormsg="格式错误，请重新输入"
                                                 ignore="ignore">
                                          <ul class="relation radius guanlian" id="img-classUl1">

                                          </ul>
                                      </div>
                                      <span class="Validform_checktip"></span>
                                  </span>
                                        <span class="f-l pl-10 pr-10 pt-5">~</span>
                                        <span class="size-M radius col-xs-8 f-l" style="width:15%">
                                      <div style="position: relative;z-index: 900;">
                                          <input type="text" autocomplete="off" class="input-text radius"
                                                 name="imgClass2" placeholder="请选择二级分类" id="imgClass2"
                                                 datatype="/^[a-zA-Z0-9\u4e00-\u9fa5、]{0,20}$/" errormsg="格式错误，请重新输入"
                                                 ignore="ignore">
                                          <ul class="relation radius guanlian" id="img-classUl2">
                                          </ul>
                                      </div>
                                      <span class="Validform_checktip"></span>
                                  </span>
                                        <span class="f-l pl-10 pr-10 pt-5">~</span>
                                        <span class="size-M radius col-xs-8" style="width:15%">
                                      <div style="position: relative;z-index: 900;">
                                          <input type="text" autocomplete="off" class="input-text radius"
                                                 name="imgClass3" placeholder="请选择三级分类" id="imgClass3"
                                                 datatype="/^[a-zA-Z0-9\u4e00-\u9fa5、]{0,20}$/" errormsg="格式错误，请重新输入"
                                                 ignore="ignore">
                                          <ul class="relation radius guanlian" id="img-classUl3">
                                          </ul>
                                      </div>
                                      <span class="Validform_checktip"></span>
                                  </span>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td class="col-3-1">
                                    <div class="row ml-10">
                                        <label class="form-label f-l pt-5">图片名称：</label>
                                        <div class="formControls col-xs-8 col-sm-9">
                                            <input type="text" class="input-text radius" name="imgname" id="imgName"
                                                   placeholder="输入图片名称关键字" datatype="/^[a-zA-Z0-9\u4e00-\u9fa5]{0,50}$/"
                                                   errormsg="格式错误，请重新输入" ignore="ignore">
                                        </div>
                                        <span class="Validform_checktip"></span>
                                    </div>
                                </td>
                                <td class="col-3-1">
                                    <div class="row ml-10">
                                        <label class="form-label f-l pt-5">SPU码：</label>
                                        <div class="formControls col-xs-8 col-sm-9">
                                            <input type="text" class="input-text radius" name="spuCode" id="spuCode"
                                                   placeholder="输入SPU码" datatype="n0-11" errormsg="格式错误，请重新输入"
                                                   ignore="ignore">
                                        </div>
                                        <span class="Validform_checktip"></span>
                                    </div>
                                </td>
                                <td class="col-3-1">
                                    <div class="row ml-10">
                                        <label class="form-label f-l pt-5">SKU码：</label>
                                        <div class="formControls col-xs-8 col-sm-9">
                                            <input type="text" class="input-text radius" name="skuCode" id="skuCode"
                                                   placeholder="输入SKU码" datatype="n0-11" errormsg="格式错误，请重新输入"
                                                   ignore="ignore">
                                        </div>
                                        <span class="Validform_checktip"></span>
                                    </div>
                                </td>
                            </tr>
                            </thead>
                        </table>
                        <div class="text-c mb-10">
                            <input id="btn" type="submit" class="btn btn-secondary radius size-S botter powerButton 1000001954909102" value="&nbsp;查&nbsp;&nbsp;询&nbsp;">
                            <input name="" type="reset" onclick="resetDiv()" class="btn radius size-S botter ml-10 powerButton 1000001954909102" value="&nbsp;重&nbsp;&nbsp;置&nbsp;">
                        </div>
                    </form>
                    <div class="text-l pl-20 pb-10 clearfix powerButton 1000001017645877"><input class="btn radius btn-secondary-outline radius f-l" onclick="addImg()" type="button" value="新增"></div>
                    <div class="line"></div>
                    <ul id="imgListBox" class="sale_pic clearfix">
                        <!--<li><img src="../../img/cn.gif"><div class="num">编码： <span>TP001009</span></div><div class="name">名称： <span>电缆横截面图</span></div><div class="sale_pic_btn"><a href="##">修改</a><a href="##">删除</a></div></li>-->
                    </ul>
                    <div class="dataTables_wrapper goods_fanye clearfix">
                        <div class="f-r pageturning M-box3"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</article>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../../../../lib/jquery/1.9.1/jquery.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../lib/layer/2.4/layer.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../static/h-ui/js/H-ui.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../static/h-ui.admin/js/H-ui.admin.js?rev=@@hash"></script> <!--/_footer 作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../../../lib/jquery.jedate.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../lib/My97DatePicker/4.8/WdatePicker.js?rev=@@hash"></script>
<!--表单验证-->
<script type="text/javascript" src="../../../../lib/jquery.validation/1.14.0/jquery.validate.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../lib/jquery.validation/1.14.0/validate-methods.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../lib/jquery.validation/1.14.0/messages_zh.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../lib/datatables/1.10.0/jquery.dataTables.min.js?rev=@@hash"></script>
<!--权限控制-->
<script type="text/javascript" src="../../../../ht-js/power.js?rev=@@hash"></script>
<!--表单验证-->
<script type="text/javascript" src="../../../../lib/Validform/5.3.2/Validform_v5.3.2_min.js?rev=@@hash"></script>
<script src="../../../../lib/pagination/jquery.pagination.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../lib/laypage/1.2/laypage.js?rev=@@hash"></script>
<script src="../../../../ht-js/public.js?rev=@@hash"></script>
<!--验证token-->
<script src="../../../../ht-js/verifyToken.js?rev=@@hash"></script>
<script src="../../../../ht-js/dockingplatform/goods/goods-sku.js?rev=@@hash"></script>
<script>
    $(function () {
        sessionStorage.removeItem("scene_lable");
        sku_cha();
        $("#picForm").Validform({
            tiptype: 2,
            callback: function (form) {
                img_list();
                return false;
            }
        });
        $("#goodSkuForm").Validform({
            tiptype: 2,
            callback: function (form) {
                sku_cha();
                return false;
            }
        });
        // 判断是否从订单跳转至sku详情
        if (sessionStorage.getItem("spuId_order") == null || sessionStorage.getItem("spuId_order") == undefined || sessionStorage.getItem("spuId_order") == ''){
            spuNameCache();
        } else {
            $.ajax({
                type: "POST",
                url: root.goodsInter.goods_getSpuDetail,
                cache: false,  //禁用缓存
                dataType: "json",
                data: {
                    spuId: sessionStorage.getItem("spuId_order")
                },
                success: function (data) {
                    if(data.errorCode == 0){
                        var spuCode = "SPU码：" + data.spu.spu_code;
                        var spuName = "商品名称：" + data.spu.name;
                        document.getElementById("spuId_title").innerHTML = spuCode;
                        document.getElementById("spuName_title").innerHTML = spuName;
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
        }
    });
    /*搜索时间初始化*/
    function timeSet(startEl,endEl,timeFormat){
        /*startEl=>开始时间Input的id，endEl=>结束时间Input的id，时间格式（YYYY-MM-DD hh:mm:ss  YYYY年MM月DD日 hh:mm:ss）*/
        /*时间设置*/
        var start = {
            format: timeFormat,
            maxDate: $.nowDate(),
            okfun: function(obj){
                end.minDate = obj.val; //开始日选好后，重置结束日的最小日期
            }
        };
        var end = {
            format: timeFormat,
            maxDate: $.nowDate(),
            okfun: function(obj){
                start.maxDate = obj.val; //将结束日的初始值设定为开始日的最大日期
            }
        };
        $.jeDate(startEl,start);
        $.jeDate(endEl,end);
    }
    timeSet("#timemin","#timemax","YYYY-MM-DD");
    timeSet("#creatimemin","#creatimemax","YYYY-MM-DD");

    jQuery.Huitab = function (tabBar, tabCon, class_name, tabEvent, i) {
        var $tab_menu = $(tabBar);
        // 初始化操作
        $tab_menu.removeClass(class_name);
        $(tabBar).eq(i).addClass(class_name);
        $(tabCon).hide();
        $(tabCon).eq(i).show();

        $tab_menu.bind(tabEvent, function () {
            $tab_menu.removeClass(class_name);
            $(this).addClass(class_name);
            var index = $tab_menu.index(this);
            $(tabCon).hide();
            $(tabCon).eq(index).show()
        })
    }

    $(function () {
        $.Huitab("#tab_topnav .tabBar span", "#tab_topnav .tabCon", "current", "click", "0")
    });
    // #tab_demo 父级id
    // #tab_demo .tabBar span 控制条
    // #tab_demo .tabCon 内容区
    // click 事件 点击切换，可以换成mousemove 移动鼠标切换
    // 1	默认第2个tab为当前状态（从0开始）

    /*------------------------------------商品图片管理--------------------------------------------------*/
    function imgGoods_listCategory(categoryLevel) {
        var categoryName = $("#imgClass1").val();
        var user_data = {
            categoryLevel: categoryLevel,
            categoryName: $("#imgClass1").val(),
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if (data.errorCode == "0") {
                if (data.data == null) {
                    classStr = "<li>无数据</li>"
                    $("#img-classUl1").html(classStr);
                } else {
                    var classStr = "";
                    for (var i = 0; i < data.data.length; i++) {
                        classStr += "<li onclick='imgNextClass(" + data.data[i].category_id + "," + data.data[i].category_level + ",\"" + data.data[i].category_name + "\")'>" + data.data[i].category_name + "</li>"
                    }
                    $("#img-classUl1").html(classStr);
                }
            }
        }
        web.doAjax(root.goodsInter.categoryByParam, 'post', user_data, succCallBack);
    }

    //获取光标
    $("#imgClass1").focus(function () {
        $("#img-classUl1").show();
        imgGoods_listCategory(1, 1);
    });
    $(document).bind("click", function (e) {
//id为menu的是菜单，id为open的是打开菜单的按钮
        if ($(e.target).closest("#img-classUl1").length == 0 && $(e.target).closest("#imgClass1").length == 0) {
//点击id为menu之外且id不是不是open，则触发
            $("#img-classUl1").hide()
        }
    });
    var oneCategoryId = "";
    var twoCategoryId = "";
    var threeCategoryId = "";

    // 2,3,4级的模糊查询
    function imgGetNext_input(level, category_id) {
        if (level < 4) {
            $("#imgClass" + level + "")[0].oninput = function () {
                console.log($("#imgClass" + level + "").val())
                if (level == 1) {
                    oneCategoryId = category_id;
                } else if (level == 2) {
                    twoCategoryId = category_id;
                } else if (level == 3) {
                    threeCategoryId = category_id;
                }
                var user_data = {
                    parentCateId: category_id,
                    categoryName: $("#imgClass" + level + "").val()
                }
                var succCallBack = function (data, status, response) {
                    console.log(data)
                    if (data.errorCode == "0") {
                        if (data.data == null) {
                            classStr = "<li>无数据</li>";
                        } else {
                            var classStr = "";
                            for (var i = 0; i < data.data.length; i++) {
                                classStr += "<li onclick='imgNextClass(" + data.data[i].category_id + "," + data.data[i].category_level + ",\"" + data.data[i].category_name + "\")'>" + data.data[i].category_name + "</li>"
                            }
                        }
                        if (data.data[0] == undefined) {
                            classValue = category_id;
                            var nextLevel = level + 1;
                            $("#img-classUl" + nextLevel + "").html(classStr);
                            $("#img-classUl" + level + "").hide();
                        } else {
                            var nextLevel = data.data[0].category_level;
                            $("#img-classUl" + nextLevel + "").html(classStr);
                            $("#img-classUl" + level + "").show();
                        }
                    }
                }
                web.doAjax(root.goodsInter.categoryByParam, 'post', user_data, succCallBack);
            }
//获取光标
            $("#imgClass" + level + "").focus(function () {
                $("#img-classUl" + level + "").show();
            });
            $(document).bind("click", function (e) {
//id为menu的是菜单，id为open的是打开菜单的按钮
                if ($(e.target).closest("#img-classUl" + level + "").length == 0 && $(e.target).closest("#imgClass" + level + "").length == 0) {
//点击id为menu之外且id不是不是open，则触发
                    $("#img-classUl" + level + "").hide()
                }
            });
        }

    }

    function imgNextClass(category_id, level, category_name) {
        if (level == 1) {
            $("#imgClass2").val("");
            $("#imgClass3").val("");
        } else if (level == 2) {
            $("#imgClass3").val("");
        }
        if (level == 1) {
            oneCategoryId = category_id;
        } else if (level == 2) {
            twoCategoryId = category_id;
        } else if (level == 3) {
            threeCategoryId = category_id;
        }
        $("#imgClass" + level + "").val(category_name)
        var user_data = {
            parentCateId: category_id
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if (data.errorCode == "0") {
                if (data.data == null) {
                    classStr = "<li>无数据</li>";
                } else {
                    var classStr = "";
                    for (var i = 0; i < data.data.length; i++) {
                        classStr += "<li onclick='imgNextClass(" + data.data[i].category_id + "," + data.data[i].category_level + ",\"" + data.data[i].category_name + "\")'>" + data.data[i].category_name + "</li>"
                    }
                }
                if (data.data[0] == undefined) {
                    classValue = category_id;
                    var nextLevel = level + 1;
                    $("#img-classUl" + nextLevel + "").html(classStr);
                    $("#img-classUl" + level + "").hide();
                } else {
                    var nextLevel = data.data[0].category_level;
                    $("#img-classUl" + nextLevel + "").html(classStr);
                    $("#img-classUl" + nextLevel + "").show();
                    $("#img-classUl" + level + "").hide()
                }
            }
        }
        imgGetNext_input(level + 1, category_id);
        web.doAjax(root.goodsInter.categoryByParam, 'post', user_data, succCallBack);
    }

    var totalPage = 1;

    function img_list() {

        var categoryName = $("#imgClass3").val();
        var firstCategoryName = $("#imgClass1").val();
        var secondCategoryName = $("#imgClass2").val();
        if (categoryName == "" || categoryName == undefined || categoryName == null) {
            threeCategoryId = -1;
        }

        if (firstCategoryName == "" || firstCategoryName == undefined || firstCategoryName == null) {
            oneCategoryId = -1;
        }

        if (secondCategoryName == "" || secondCategoryName == undefined || secondCategoryName == null) {
            twoCategoryId = -1;
        }

        $.ajax({
            contentType: "application/json",
            type: "POST",
            url: root.goodsInter.goods_listImg,
            cache: false,  //禁用缓存
            dataType: "json",
            data: JSON.stringify({
                "pageSize": "50",
                "nowPage": 1,
                "model": {
                    "spuCode": $("#spuCode").val(),
                    "skuCode": $("#skuCode").val(),
                    "imgName": $("#imgName").val(),
                    "oneCategoryId": oneCategoryId,
                    "twoCategoryId": twoCategoryId,
                    "threeCategoryId": threeCategoryId
                }
            }),
            success: function (data) {
                if (data.errorCode == 0) {
                    var imgHtmlStr = "";
                    var objList = data.data.list;
                    if (objList != null) {
                        for (var i = 0; i < data.data.list.length; i++) {
                            if (objList[i].img_name == null || objList[i].img_name == "null") {
                                objList[i].img_name = "";
                            }
                            if (objList[i].img_url != null && objList[i].img_url != "null") {
                                if (objList[i].use_img == 0) {
                                    imgHtmlStr += '<li><img onclick="picShow(\'查看图片\',\'picShow.html\',\'' + objList[i].img_url + '\',\'500\',\'300\',\'110\')" src="' + objList[i].img_url + '"><div class="num">编码： <span>' + objList[i].img_id + '</span></div><div class="name">名称： <span>' + objList[i].img_name + '</span></div><div class="sale_pic_btn"><a onclick="updataImg(' + objList[i].img_id + ')">修改</a><a onclick="deleteImg(' + objList[i].img_id + ')">删除</a></div></li>';
                                } else if (objList[i].use_img == 1) {
                                    imgHtmlStr += '<li><img onclick="picShow(\'查看图片\',\'picShow.html\',\'' + objList[i].img_url + '\',\'500\',\'300\',\'110\')" src="' + objList[i].img_url + '"><div class="num">编码： <span>' + objList[i].img_id + '</span></div><div class="name">名称： <span>' + objList[i].img_name + '</span></div><div class="sale_pic_btn"></div></li>';
                                }
                            }
                        }
                        $("#imgListBox").html(imgHtmlStr);
                    }
                    totalPage = data.data.totalPage;
                    $('.M-box3').pagination({
                        pageCount: totalPage,
                        jump: true,
                        coping: true,
                        prevContent: '上页',
                        nextContent: '下页',
                        callback: function (api) {
                            console.log(api.getCurrent());
                            $.ajax({
                                contentType: "application/json",
                                type: "POST",
                                url: root.goodsInter.goods_listImg,
                                cache: false,  //禁用缓存
                                dataType: "json",
                                data: JSON.stringify({
                                    "pageSize": "50",
                                    "nowPage": api.getCurrent(),
                                    "model": {
                                        "spuCode": $("#spuCode").val(),
                                        "skuCode": $("#skuCode").val(),
                                        "imgName": $("#imgName").val(),
                                        "oneCategoryId": oneCategoryId,
                                        "twoCategoryId": twoCategoryId,
                                        "threeCategoryId": threeCategoryId
                                    }
                                }),
                                success: function (data) {
                                    console.log(data);
                                    if (data.errorCode == 0) {
                                        var imgHtmlStr = "";
                                        var objList = data.data.list;
                                        if (objList != null) {
                                            for (var i = 0; i < data.data.list.length; i++) {
                                                if (objList[i].img_name == null || objList[i].img_name == "null") {
                                                    objList[i].img_name = "";
                                                }
                                                if (objList[i].img_url != null && objList[i].img_url != "null") {
                                                    if (objList[i].use_img == 0) {
                                                        imgHtmlStr += '<li><img onclick="picShow(\'查看图片\',\'picShow.html\',\'' + objList[i].img_url + '\',\'500\',\'300\',\'110\')" src="' + objList[i].img_url + '"><div class="num">编码： <span>' + objList[i].img_id + '</span></div><div class="name">名称： <span>' + objList[i].img_name + '</span></div><div class="sale_pic_btn"><a onclick="updataImg(' + objList[i].img_id + ')">修改</a><a onclick="deleteImg(' + objList[i].img_id + ')">删除</a></div></li>';
                                                    } else if (objList[i].use_img == 1) {
                                                        imgHtmlStr += '<li><img onclick="picShow(\'查看图片\',\'picShow.html\',\'' + objList[i].img_url + '\',\'500\',\'300\',\'110\')" src="' + objList[i].img_url + '"><div class="num">编码： <span>' + objList[i].img_id + '</span></div><div class="name">名称： <span>' + objList[i].img_name + '</span></div><div class="sale_pic_btn"></div></li>';
                                                    }
                                                }
                                            }
                                            $("#imgListBox").html(imgHtmlStr);
                                        }
                                        totalPage = data.data.totalPage
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    alert(XMLHttpRequest);
                                }
                            });
                        }
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest);
            }
        });
    }

    function picShow(title, url, imgUrl, w, h) {
        window.event ? window.event.cancelBubble = true : e.stopPropagation();
        sessionStorage.setItem("imgUrl", imgUrl);
        layer_show(title, url, "800", "500");
    }

    function addImg() {
        layer_show("增加图片", "addPic.html", "600", "400");
    }

    function updataImg(imgId) {
        $.ajax({
            contentType: "application/json",
            type: "POST",
            url: root.goodsInter.goods_getImg,
            cache: false,  //禁用缓存
            dataType: "json",
            data: JSON.stringify({
                "imgId": imgId
            }),
            success: function (data) {
                console.log(data);
                if (data.errorCode == 0) {
                    if (data.use_img == 0) {
                        // 未使用，随便修
                        sessionStorage.setItem("imgInfo", JSON.stringify(data));
                        layer_show("修改图片", "can-updataImg.html", "600", "400");
                    } else if (data.use_img == 1) {
                        //已使用，只能修改名字
                        sessionStorage.setItem("imgInfo", JSON.stringify(data));
                        layer_show("修改图片", "cannot-updataImg.html", "600", "400");
                    }
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest);
            }
        });
    }

    function deleteImg(imgId) {
        console.log(imgId)
        $.ajax({
            contentType: "application/json",
            type: "POST",
            url: root.goodsInter.goods_delImg,
            cache: false,  //禁用缓存
            dataType: "json",
            data: JSON.stringify({
                "imgId": imgId
            }),
            success: function (data) {
                console.log(data);
                if (data.errorCode == 0) {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                    layer.msg("删除成功", {icon: 6, time: 1000}, function () {
                        img_list();
                    });
                } else {
                    layer.msg(data.errorMessage, {icon: 5, time: 1000}, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest);
            }
        });
    }
</script>
</body>
</html>